﻿'// ========================================================================= '
'// ------------------------------------------------------------------------- '
'//!				\file		CM_3DPoints.vb
'			        \date		june 2010
'			        \author		TNick
'
'			        \brief		
'
'
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   This file is considered universal knowledge. No restrictions
'   are imposed; use as you see fit.
'   Please read ReadMe.txt and Licence.txt in root folder
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'   
'   Edit functionality is to be tested / debugged
'
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
'//
'//
'//
'//
'//  IMPORTS     ------------------------------------------------------------ '
#Region "Imports"

    Imports System

#End Region
'//  IMPORTS     ============================================================ '
'//
'//
'//
'//
'//  DEFINITIONS    --------------------------------------------------------- '

'//  DEFINITIONS    ========================================================= '
'//
'//
'//
'//
'//  DATA    ---------------------------------------------------------------- '


'//  DATA    ================================================================ '
'//
'//
'//
'//
'//  CLASS    --------------------------------------------------------------- '

Public Class IniWork


    '// --------------------------------------------------------------------- '
    '// DATA
    Private sFileHand As String = Nothing
    Private bErr As Boolean = True
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Public ReadOnly Property HasErrors As Boolean
        Get
            Return bErr
        End Get
    End Property
    '// ===================================================================== '


    '// --------------------------------------------------------------------- '
    Public Sub New (ByVal sFile As String)
        If (io.File.Exists(sFile) = False) Then
            bErr = True
            Return
        End If
        sFileHand = sFile
        bErr = False
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Public Function Read(ByRef sSection As String, _
                         ByRef sKey As String, _
                         ByRef sDefVal As String) As String
        
        Dim bInOurSection As Boolean = False
        Dim bInOurValue As Boolean = False
        Dim bSkipValue As Boolean = False
        Dim sOut As String = sDefVal
        Dim sTrimUpr As String
        Dim sInputLine As String
        Dim srFileReader As System.IO.StreamReader = Nothing
        Try
            srFileReader = System.IO.File.OpenText(sFileHand)
            sInputLine = srFileReader.ReadLine()
            Do Until sInputLine Is Nothing
                sTrimUpr = sInputLine.Trim().ToUpper()
                '// we have found our string and we're adding strings
                If (bInOurValue = True) Then
                    If (sTrimUpr = "{") Then
                        GoTo NextLine
                    End If
                    If (sTrimUpr = "}") Then
                        Exit Try
                    End If
                    sOut = sOut & sInputLine & vbNewLine
                    GoTo NextLine
                End If
                '// skip comment lines
                If (sTrimUpr.StartsWith(";")) Then GoTo NextLine
                '// skip multi-line values
                If (bSkipValue = True) Then
                    If (sTrimUpr = "}") Then
                        bSkipValue = False
                    End If
                    GoTo NextLine
                End If
                '// detect the start of multiline values
                If (sTrimUpr.StartsWith("{")) Then
                    If (bInOurValue = True) Then
                        bSkipValue = True
                    Else
                        GoTo NextLine
                    End If
                End If
                If (sTrimUpr.Length > 3) Then
                    If ((sTrimUpr.StartsWith("[") AndAlso _
                        (sTrimUpr.EndsWith("]")))) Then
                        '// we have a section start
                        If bInOurSection = False Then
                            If (sTrimUpr.Substring(1,sTrimUpr.Length-2) = _
                                    sSection.ToUpper()) Then
                                '// we have our section
                                bInOurSection = True
                            End If
                        Else
                            '// reached the end of our section and 
                            '// found nothing
                            Exit Try
                        End If
                    Else If bInOurSection = True Then
                        '// we have to search for a value=key pair
                        Dim i As Integer
                        i = sTrimUpr.IndexOf("=")
                        If (i < 0) Then
                            '// entire name is the name of the value
                            If (sTrimUpr = sKey.ToUpper()) Then
                                '// we have found the key
                                bInOurValue = True
                                sOut = ""
                            End If
                        Else
                            If (sTrimUpr.Substring(0, i) = sKey.ToUpper()) Then
                                '// we have found the value
                                bInOurValue = True
                                sOut = ""
                            End If
                        End If
                    End if
                End If
                NextLine:
                sInputLine = srFileReader.ReadLine()
            Loop
        Finally
            If Not (srFileReader Is Nothing) Then
                srFileReader.Close()
            End if
            GC.Collect()
            GC.WaitForPendingFinalizers()
        End try
        Return sOut
    End Function
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Public Sub Write(ByRef sSection As String, _
                     ByRef sKey As String, _
                     ByRef sValue As String)



        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub
    '// ===================================================================== '


End Class

'//  CLASS    =============================================================== '
'//
'//
'//
'//
'//  FUNCTIONS    ----------------------------------------------------------- '

'//  FUNCTIONS    =========================================================== '
'//
'//
'//
'//
'// ------------------------------------------------------------------------- '
'// ========================================================================= '





